package logic

import (
	"context"
	"fmt"
	"teatch/model/mysql"

	"teatch/teacherrpc/internal/svc"
	"teatch/teacherrpc/teacherrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseAddLogic {
	return &CourseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 课程添加
func (l *CourseAddLogic) CourseAdd(in *teacherrpc.CourseAddRequest) (*teacherrpc.CourseAddResponse, error) {
	// todo: add your logic here and delete this line

	if in.Content == "" || in.Types == "" || in.Title == "" {
		return nil, fmt.Errorf("各个字段不得为空")
	}

	data := mysql.Course{
		TeachersId: int(in.TeachersId),
		Title:      in.Title,
		Types:      in.Types,
		Content:    in.Content,
	}

	mysql.DB.Create(&data)
	return &teacherrpc.CourseAddResponse{
		CourseId: int64(data.ID),
	}, nil
}
